﻿using MongoDB.Driver;
using Sustainalytics.ClientDW.Entities;
using System.Collections.Generic;

namespace Sustainalytics.ScreeningTool.Synchronization.Handlers
{
    public class FinancialDataHandler : IHandler<FinancialData>
    {
        public ProjectionDefinition<FinancialData> GetProjection(ProjectionDefinitionBuilder<FinancialData> builder) => builder
            .Include(x => x.Timestamps)
            .Include(x => x.NEBT)
            .Include(x => x.NetIncome)
            .Include(x => x.MarketCapitalization)
            .Include(x => x.TotalRevenues);

        public IEnumerable<ExtraElement> GetExtraElements(FinancialData entity)
            => GetExtraElements(entity, entity.Timestamps ?? new FinancialDataTimestamps());

        public IEnumerable<ExtraElement> GetExtraElements(FinancialData x, FinancialDataTimestamps t)
            => new ExtraElementList
            {
                { "NEBT",                 x.NEBT.Round(2),                 t.EBIT                 },
                { "Net Income",           x.NetIncome.Round(2),            t.NetIncome            },
                { "Market cap (mln USD)", x.MarketCapitalization.Round(2), t.MarketCapitalization },
                { "Total Revenues",       x.TotalRevenues.Round(2),        t.TotalRevenues        },
            };
    }
}
